#include "log/log.h"
#include "cJSON/cJSON.h"

int main(void)
{
    char *name = "zhangsan";
    int age = 18;
    // 创建json对象
    cJSON *root = cJSON_CreateObject();
    cJSON_AddStringToObject(root, "name", name);
    cJSON_AddNumberToObject(root, "age", age);
    // 将json对象转换成字符串
    char *json_str = cJSON_PrintUnformatted(root);
    log_debug("json_str: %s", json_str);
    // 将字符串转换成json对象
    cJSON *root2 = cJSON_Parse(json_str);
    cJSON *name_json = cJSON_GetObjectItem(root2, "name");
    cJSON *age_json = cJSON_GetObjectItem(root2, "age");
    log_debug("name: %s, age: %d", name_json->valuestring, age_json->valueint);
    return 0;
}